package com.joplus.housekeeper.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.AbsListView;

import com.joplus.housekeeper.ui.view.swipeMenuListview.SwipeMenuListView;

/**
 * Created by Administrator on 2017/1/22.
 *
 *
 * 这里是侧滑删除列表
 */

public class SwapLoadMoreListView extends SwipeMenuListView implements AbsListView.OnScrollListener{



    private int lastItem;

    private int mTotalItemCount;
    public SwapLoadMoreListView(Context context) {
        super(context);
    }

    public SwapLoadMoreListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public SwapLoadMoreListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    private LoadMoreListView.OnLoadMoreListener onLoadMoreListener;

    public void setOnLoadMoreListener(LoadMoreListView.OnLoadMoreListener onLoadMoreListener) {
        this.onLoadMoreListener = onLoadMoreListener;
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        if (lastItem == mTotalItemCount && scrollState == OnScrollListener.SCROLL_STATE_IDLE) {

            if (onLoadMoreListener != null) {
                onLoadMoreListener.onLoadMore();
            }
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {

        return super.onTouchEvent(ev);
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        lastItem = firstVisibleItem + visibleItemCount ;
        mTotalItemCount = totalItemCount;
    }
}
